/**
 * @Author: Your name
 * @Date:   2024-03-15 18:15:53
 * @Last Modified by:   Your name
 * @Last Modified time: 2024-03-15 18:16:37
 */
var mysql = require('mysql');
var moduleDB = require('../../db/db'); // 引入数据模型
// 连接 mysql 数据库
var conn = mysql.createConnection(moduleDB.mysql);
conn.connect((err) => {
  if (err) throw err;
  console.log('Connected to the MySQL server!');
});

export default async (req, res) => {
  try {
    const query = 'SELECT * FROM note'; // 替换为你的表名
    conn.query(query, (error, results, fields) => {
      if (error) throw error;
      res.status(200).json(results);
    });
  } catch (error) {
    console.error(error);
    res.status(500).json({ error: 'An error occurred' });
  }
};
